package com.shop.cereshop.app.dl.logic.controller;

import com.shop.cereshop.app.dl.logic.domian.CareShopNews;
import com.shop.cereshop.app.dl.logic.service.CareShopNewsService;
import com.shop.cereshop.app.dl.logic.utils.ResultInfo;
import com.shop.cereshop.app.service.buyer.CereBuyerUserService;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.utils.EmptyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 况鑫威
 * @Date: 2021/6/15
 * @Time: 13:53
 * @ClassName: DlCareShopNewsController
 * @Description: com.shop.cereshop.business.dl.logic.controller
 */
@RestController
@RequestMapping("/api")
@CrossOrigin
public class DlCareShopNewsController {
    @Autowired
    private CareShopNewsService careShopNewsService;
    @Autowired
    private CereBuyerUserService cereBuyerUserService;

    /**
     * 功能描述: 资讯详情
     *
     * @Return: com.shop.cereshop.business.dl.logic.utils.ResultInfo
     * @Author: 况鑫威
     * @Date: 2021/6/15
     * @Time: 16:25
     */
    @PostMapping("/getNewsParticulars")
    public ResultInfo<?> getNewsParticulars(Long newsId, HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        CereBuyerUser user = null;
        if (!EmptyUtils.isEmpty(token)) {
            //根据token查询用户信息
            user = cereBuyerUserService.findByToken(token);
        }
        CareShopNews careShopNews = careShopNewsService.selectByPrimaryKey(newsId);
        if (user!=null){
            careShopNews.setUserId(user.getBuyerUserId());
        }
        return new ResultInfo<>(careShopNews);
    }
}
